import * as api from "./api";
import { CreateCrudOptionsProps, CreateCrudOptionsRet, dict } from "@fast-crud/fast-crud";
import { request } from "/@/api/service";

export default function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  const pageRequest = async (query) => {
    return await api.GetList();
  };
  const editRequest = async ({ form, row }) => {
    form.id = row.id;
    return await api.UpdateObj(form);
  };
  const delRequest = async ({ row }) => {
    return await api.DelObj(row.id);
  };
  const addRequest = async ({ form }) => {
    return await api.AddObj(form);
  };
  return {
    crudOptions: {
      request: {
        pageRequest,
        delRequest,
        addRequest,
        editRequest
      },
      columns: {
        id: {
          title: "ID",
          type: "number",
          form: { show: false },
          column: { width: 60 }
        },
        category: {
          title: "类别",
          type: "dict-select",
          dict: dict({
            data: [
              { label: "失物", value: "lost" },
              { label: "招领", value: "found" }
            ]
          })
        },
        name: {
          title: "联系人",
          type: "string"
        },
        tel: {
          title: "联系电话",
          type: "string",
          form: {
            component: {
              props: { maxlength: 20 }
            }
          }
        },
        description: {
          title: "描述",
          type: "string",
          form: {
          }
        },
        imgs: {
          title: "图片",
          type: "string",
          column: {
            component: { name: "fs-images" }
          }
        },
        time: {
          title: "时间",
          type: "datetime",
          form: {
          }
        },
        location: {
          title: "地点",
          type: "string"
        }
      }
    }
  };
}
